package com.gz.rabbitmq.ps;

import com.gz.rabbitmq.utils.ConnectionUtil;
import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

public class Product {

    public static String EX_CHANGE_NAE = "fanout_exchange";

    public static String FANOUT_QUEUE_1 = "fanout_queue_1";

    public static String FANOUT_QUEUE_2 = "fanout_queue_2";

    public static void main(String[] args) throws IOException, TimeoutException {
        Connection connection = ConnectionUtil.getConnection("demo");

        Channel channel = connection.createChannel();

        //声明交换机
        channel.exchangeDeclare(EX_CHANGE_NAE, BuiltinExchangeType.FANOUT);

        //创建队列
        channel.queueDeclare(FANOUT_QUEUE_1, true, false, false, null);

        //创建队列
        channel.queueDeclare(FANOUT_QUEUE_2, true, false, false, null);

        //队列绑定到交换机
        channel.queueBind(FANOUT_QUEUE_1, EX_CHANGE_NAE, "");

        channel.queueBind(FANOUT_QUEUE_2, EX_CHANGE_NAE, "");

        for (int i = 0; i < 30; i++) {
            channel.basicPublish(EX_CHANGE_NAE, "", null, new StringBuilder().append(i).append("=========work模式测试").toString().getBytes());
        }

        channel.close();
        connection.close();
    }
}
